import React, { Component } from "react";
import Child1 from "./Child1";
import Child2 from "./Child2";

class App extends Component {
  state = {
    num: undefined,
  };

  fn(num) {
    // console.log("fn", num);
    this.setState({
      num,
    });
  }

  render() {
    return (
      <>
        <h2>状态提升 - {this.state.num}</h2>
        {/* 子传父也是通过自定义事件 */}
        {/* 让子组件去触发父组件的事件 */}
        {/* 触发事件的时候就可以去传递参数 */}
        <Child1 onGetNum={this.fn.bind(this)} />
        <Child2 num={this.state.num} />
      </>
    );
  }
}

export default App;
